package 真题;/**
 * @author： li
 * @date： 2022-04-01 16:13
 * @version 1.0
 */
import java.math.BigDecimal;
import java.util.*;
public class 路径 {
    static int N=2021;
    static long[][] g = new long[N+1][N+1];
    static int[][] vis = new int[N+1][N+1];
    static class node{
        private int x;
        private int y;
        private long dis;

        public node(int x, int y, long dis) {
            this.x = x;
            this.y = y;
            this.dis = dis;
        }
    }
    static boolean check(int x,int y){
        if(x<1||y>N||x>N||y<1||g[x][y]==0||vis[x][y]==1)
            return false;
        return true;
    }
    static long bfs(int x,int y){
        long dist=0;
        Queue<node> q = new LinkedList<>();
        q.offer(new node(1,1,0));
        while(!q.isEmpty()){
            long min=Long.MAX_VALUE;
            node p =q.poll();
            if(p.x==2021&&p.y==2021) return dist;
            for(int i=1;i<=2021;i++){
                if(g[p.y][i]!=0&&check(p.y,i)) {
                    vis[p.y][i] = 1;
                    min=Math.min(min,g[p.y][i]);
                    q.offer(new node(p.y,i,p.dis+g[p.y][i]));
                }
            }
            dist+=min;
        }
        return -1;
    }
    //最大公约数
    static int gcd(int a,int b){
        return b>0?gcd(b,a%b):a;
    }
    //最小公倍数
    static int lcm(int a,int b){
        return a*b/gcd(a,b);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
//        int a,b;
//        a =sc.nextInt();
//        b =sc.nextInt();

        for(int i=1;i<=2021;i++)
            for(int j=1;j<=2021;j++){
                if(Math.abs(i-j)<=21){
                    g[i][j]=lcm(i,j);
                    g[j][i]=lcm(i,j);
                }
                else
                    g[i][j]=0x3f3f3f3f;
            }

//        System.out.println(bfs(a,b));
        for(int k=1;k<=2021;k++){
            for(int i=1;i<=2021;i++){
                for(int j=1;j<=2021;j++){
                    g[i][j]=Math.min(g[i][j],g[i][k]+g[k][j]);
                }
            }
        }
        System.out.println(g[1][2021]);
    }
}
